/* Copyright 2011 Rok Lenarčič 
 * 
 * This file is a part of MicroFn.
 * 
 * MicroFn is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * MicroFn is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/> */
package net.rlenar.microfn;

public enum JVM {
	IBM(false),
	OTHER(true);
	public static final JVM currentJVM;
	static {
		String vendor = (String) System.getProperties().get("java.vendor");
		if (vendor != null && vendor.startsWith("IBM")) {
			currentJVM = IBM;
		} else {
			currentJVM = OTHER;
		}
	}
	private final boolean hasStringCopyConstructor;
	private JVM(boolean hasStringCopyConstructor) {
		this.hasStringCopyConstructor = hasStringCopyConstructor;
	}
	private static final String emptyStr = new String();
	public String copyString(String str) {
		if (hasStringCopyConstructor) {
			return new String(str);
		} else {
			// why this weird method of making a copy?
			// because IBM JVM has no public copy constructor and this is the only way
			// of copying a string without copying the char array twice
			// IBM should stop screwing with java core classes just to score higher
			// on benchmarks as this screws with everyone's code
			// even their own RAD IDE has huge memory leaks because of this			
			return emptyStr.concat(str);
		}
	}
}
